package com.whut.mall.controller;

import com.github.pagehelper.PageInfo;
import com.whut.mall.common.ApiRestResponse;
import com.whut.mall.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xh
 * @date 2022/5/16 17:06
 * 订单后台管理Controller
 */
@RestController
public class OrderAdminController {

    @Autowired
    OrderService orderService;

    @GetMapping("admin/order/list")
    @ApiOperation("后台订单列表")
    public ApiRestResponse listForAdmin(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize){
        PageInfo pageInfo = orderService.listForAdmin(pageNum,pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    /**
     * @param orderNo
     * @return
     * 发货，订单流程状态: 0 用户已取消
     *                  10 未付款
     *                  20 已付款    这时候之后才能发货
     *                  30 已发货
     *                  40 交易完成
     */
    @PostMapping("admin/order/delivered")
    @ApiOperation("管理员发货")
    public ApiRestResponse delivered(@RequestParam String orderNo){
        orderService.deliver(orderNo);
        return ApiRestResponse.success();
    }

    /**
     * @param orderNo
     * @return
     * 用户和管理员均可完结订单
     * 发货，订单流程状态: 0 用户已取消
     *                  10 未付款
     *                  20 已付款
     *                  30 已发货      管理员和用户都可以调用
     *                  40 交易完成
     */
    @PostMapping("order/finish")
    @ApiOperation("完结订单")
    public ApiRestResponse finish(@RequestParam String orderNo){
        orderService.finish(orderNo);
        return ApiRestResponse.success();
    }

}
